package com.bookmanager.www.common.utils;

import org.apache.commons.mail.HtmlEmail;

/**
 * Created with IntelliJ IDEA.
 *
 * @author: 风离
 * @Date: 2021/10/01/21:52
 * @Description:
 */
public class EmailUtils {



    //发送账号密码邮件通知
    public static boolean sendMessageToUser(String email1,String password)
    {
        try {
            HtmlEmail email = new HtmlEmail();
            email.setHostName("smtp.qq.com");
            email.setCharset("UTF-8");
            email.addTo(email1);

            email.setFrom("1906249650@qq.com", "风离");

            email.setAuthentication("1906249650@qq.com", "qvoyzsrwndrybbge");

            email.setSubject("读者书店欢迎您");
            email.setMsg("尊敬的读者书店用户您好,您本次注册的账号是:【" + email1+"】密码为：【"+password+"】请妥善保管嗷~");
            email.send();
            return true;
        }
        catch(Exception e){
            e.printStackTrace();
            return false;
        }
    }

    //邮箱验证码
    public static boolean sendEmail(String emailaddress,String code,String codeType){
        try {
            HtmlEmail email = new HtmlEmail();
            email.setHostName("smtp.qq.com");
            email.setCharset("UTF-8");
            email.addTo(emailaddress);

            email.setFrom("1906249650@qq.com", "风离");

            email.setAuthentication("1906249650@qq.com", "qvoyzsrwndrybbge");

            email.setSubject("读者书店欢迎您");
            if (codeType.equals("1"))
            {
                email.setMsg("尊敬的读者书店用户您好,您本次注册的验证码是:" + code+"  本次验证码五分钟有效嗷~");//此处填写邮件内容
            }else if(codeType.equals("2")) {
                email.setMsg("尊敬的读者书店用户您好,您本次修改邮箱的验证码是:" + code+"  本次验证码五分钟有效嗷~");//此处填写邮件内容
            }else if(codeType.equals("3"))
            {
                email.setMsg("尊敬的读者书店用户您好,您本次解绑邮箱的验证码是:" + code+"  本次验证码五分钟有效嗷~");//此处填写邮件内容
            }

            email.send();
            return true;
        }
        catch(Exception e){
            e.printStackTrace();
            return false;
        }
    }
}
